﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CocisDAL;
using CocisModel;
using CocisModel.Common;
using System.Data;
using CocisWeb.src;

namespace CocisWeb.ManageAsset
{
    public partial class AddGeneralSoftware : BasePage
    {
        public AssetDAL dal = new AssetDAL();
        public LogsDAL logs = new LogsDAL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.BindDropDownList();
            }
        }
        public void BindDropDownList()
        {
            this.ddlSiteCode.DataSource = dal.GetSiteCode();
            this.ddlSiteCode.DataTextField = "SiteCode";
            this.ddlSiteCode.DataValueField = "SiteCodeID";
            this.ddlSiteCode.DataBind();

            this.ddlLicense.DataSource = dal.GetLicense();
            this.ddlLicense.DataTextField = "License";
            this.ddlLicense.DataValueField = "LicenseID";
            this.ddlLicense.DataBind();

            this.ddlStatus.DataSource = dal.GetStatus();
            this.ddlStatus.DataTextField = "Status";
            this.ddlStatus.DataValueField = "StatusID";
            this.ddlStatus.DataBind();

            this.ddlVendorName.DataSource = dal.GetVendor();
            this.ddlVendorName.DataTextField = "VendorName";
            this.ddlVendorName.DataValueField = "VendorID";
            this.ddlVendorName.DataBind();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Asset.GeneralSoftwareInfoDataTable dt = new Asset.GeneralSoftwareInfoDataTable();
            Asset.GeneralSoftwareInfoRow rows = dt.NewGeneralSoftwareInfoRow();
            Guid gd = new Guid();
            rows.GeneralSoftwareID = gd;
            rows.SiteCodeID = int.Parse(this.ddlSiteCode.SelectedValue.ToString());
            rows.SoftwareName = this.txtSoftwareName.Text;
            rows.SoftwareVersion = this.txtSoftwareVersion.Text;
            rows.LicenseID = int.Parse(this.ddlLicense.SelectedValue.ToString());
            rows.StatusID =int.Parse(this.ddlStatus.SelectedValue.ToString());            
            rows.WarrantyStartDate =DateTime.Parse(this.txtWarrantyStartDate.Text);
            rows.WarrantyEndDate = DateTime.Parse(this.txtWarrantyEndDate.Text);
            rows.VendorID =int.Parse(this.ddlVendorName.SelectedValue.ToString());
           
            dt.Rows.Add(rows);
            dt.AcceptChanges();

            int temp = dal.AddGeneralSoftware(dt);
            if (temp > 0)
            {
                string ip=Request.UserHostAddress.ToString();
                int t = logs.AddNewLogsInfo("insert new GeneralSoftwareInfo", LoginUser.UserName, ip);
                ClientScript.RegisterStartupScript(this.GetType(), "a", "<script language=javascript>alert('添加成功！')</script>");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "b", "<script language=javascript>alert('添加失败！')</script>");
            }
        }
       
    }
}
